<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="场所code" prop="placeCode">
        <el-input
          v-model="queryParams.placeCode"
          placeholder="请输入场所code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="场所名称" prop="placeName">
        <el-input
          v-model="queryParams.placeName"
          placeholder="请输入场所名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="房源码" prop="roomId">
        <el-input
          v-model="queryParams.roomId"
          placeholder="请输入房源码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房源名称" prop="roomName">
        <el-input
          v-model="queryParams.roomName"
          placeholder="请输入房源名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="巡检部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入巡检部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="巡检部门" prop="department">
        <el-input
          v-model="queryParams.department"
          placeholder="请输入巡检部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="巡检人员" prop="worker">
        <el-input
          v-model="queryParams.worker"
          placeholder="请输入巡检人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="巡检时间" prop="inspectionTime">
        <el-date-picker clearable
          v-model="queryParams.inspectionTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择巡检时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="整改情况" prop="rectQk">
        <el-input
          v-model="queryParams.rectQk"
          placeholder="请输入整改情况，0待核查，1已整改、2未整改、"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ptsj:inspection:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ptsj:inspection:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ptsj:inspection:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ptsj:inspection:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="inspectionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" prop="id" /> -->
      <!-- <el-table-column label="场所code" align="center" prop="placeCode" /> -->
      <el-table-column label="场所名称" align="center" prop="placeName" />
      <!-- <el-table-column label="房源码" align="center" prop="roomId" /> -->
      <el-table-column label="房源名称" align="center" prop="roomName" />
      <el-table-column label="房间问题" align="center" prop="roomProblem" />
      <!-- <el-table-column label="巡检部门id" align="center" prop="deptId" /> -->
      <el-table-column label="巡检部门" align="center" prop="department" />
      <!-- <el-table-column label="巡检单位" align="center" prop="unit" /> -->
      <el-table-column label="巡检人员" align="center" prop="worker" />
      <el-table-column label="巡检时间" align="center" prop="inspectionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inspectionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="挂牌类型" align="center" prop="cardType" />
      <!-- <el-table-column label="挂牌细则" align="center" prop="cardItem" /> -->
      <!-- <el-table-column label="整改开始时间" align="center" prop="rectStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rectStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="整改结束时间" align="center" prop="rectEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rectEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="挂牌说明" align="center" prop="cardBz" /> -->
      <!-- <el-table-column label="挂牌状态" align="center" prop="cardStatus" /> -->
      <el-table-column label="整改情况" align="center" prop="rectQk" />
      <el-table-column label="积分" align="center" prop="score" />
      <!-- <el-table-column label="创建人" align="center" prop="createdBy" /> -->
      <!-- <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ptsj:inspection:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="seeDetails(scope.row)"
          >详情</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ptsj:inspection:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改巡检信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="场所code" prop="placeCode">
          <el-input v-model="form.placeCode" placeholder="请输入场所code" />
        </el-form-item>
        <el-form-item label="场所名称" prop="placeName">
          <el-input v-model="form.placeName" placeholder="请输入场所名称" />
        </el-form-item>
        <el-form-item label="房源码" prop="roomId">
          <el-input v-model="form.roomId" placeholder="请输入房源码" />
        </el-form-item>
        <el-form-item label="房源名称" prop="roomName">
          <el-input v-model="form.roomName" placeholder="请输入房源名称" />
        </el-form-item>
        <el-form-item label="房间问题" prop="roomProblem">
          <el-input v-model="form.roomProblem" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="巡检部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入巡检部门id" />
        </el-form-item>
        <el-form-item label="巡检部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入巡检部门" />
        </el-form-item>
        <el-form-item label="巡检单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入巡检单位" />
        </el-form-item>
        <el-form-item label="巡检人员" prop="worker">
          <el-input v-model="form.worker" placeholder="请输入巡检人员" />
        </el-form-item>
        <el-form-item label="巡检时间" prop="inspectionTime">
          <el-date-picker clearable
            v-model="form.inspectionTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择巡检时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="挂牌细则" prop="cardItem">
          <el-input v-model="form.cardItem" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="整改开始时间" prop="rectStartTime">
          <el-date-picker clearable
            v-model="form.rectStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择整改开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="整改结束时间" prop="rectEndTime">
          <el-date-picker clearable
            v-model="form.rectEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择整改结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="挂牌说明" prop="cardBz">
          <el-input v-model="form.cardBz" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="整改情况，0待核查，1已整改、2未整改、" prop="rectQk">
          <el-input v-model="form.rectQk" placeholder="请输入整改情况，0待核查，1已整改、2未整改、" />
        </el-form-item>
        <el-form-item label="得分" prop="score">
          <el-input v-model="form.score" placeholder="请输入得分" />
        </el-form-item>
        <el-form-item label="删除标记" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInspection, getInspection, delInspection, addInspection, updateInspection } from "@/api/ptsj/inspection";

export default {
  name: "Inspection",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 巡检信息表格数据
      inspectionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        placeCode: null,
        placeName: null,
        roomId: null,
        roomName: null,
        roomProblem: null,
        deptId: null,
        department: null,
        unit: null,
        worker: null,
        inspectionTime: null,
        cardType: null,
        cardItem: null,
        rectStartTime: null,
        rectEndTime: null,
        cardBz: null,
        cardStatus: null,
        rectQk: null,
        score: null,
        createdBy: null,
        createdTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /* 查看详情 */
    seeDetails(row) {
      this.$router.push({path: '/see/inspection-details', query: { id: row.id }});
    },
    /** 查询巡检信息列表 */
    getList() {
      this.loading = true;
      listInspection(this.queryParams).then(response => {
        this.inspectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        placeCode: null,
        placeName: null,
        roomId: null,
        roomName: null,
        roomProblem: null,
        deptId: null,
        department: null,
        unit: null,
        worker: null,
        inspectionTime: null,
        cardType: null,
        cardItem: null,
        rectStartTime: null,
        rectEndTime: null,
        cardBz: null,
        cardStatus: null,
        rectQk: null,
        score: null,
        delFlag: null,
        createdBy: null,
        createdTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加巡检信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInspection(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改巡检信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInspection(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInspection(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除巡检信息编号为"' + ids + '"的数据项？').then(function() {
        return delInspection(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ptsj/inspection/export', {
        ...this.queryParams
      }, `inspection_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
